package com.ruoyi.project.system.versioninstruct.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.versioninstruct.domain.VersionInstruct;
import com.ruoyi.project.system.versioninstruct.service.IVersionInstructService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 版本说明Controller
 * 
 * @author ruoyi
 * @date 2021-05-24
 */
@Controller
@RequestMapping("/system/versioninstruct")
public class VersionInstructController extends BaseController
{
    private String prefix = "system/versioninstruct";

    @Autowired
    private IVersionInstructService versionInstructService;

    @RequiresPermissions("system:versioninstruct:view")
    @GetMapping()
    public String versioninstruct()
    {
        return prefix + "/versioninstruct";
    }

    /**
     * 查询版本说明列表
     */
    @RequiresPermissions("system:versioninstruct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VersionInstruct versionInstruct)
    {
        startPage();
        List<VersionInstruct> list = versionInstructService.selectVersionInstructList(versionInstruct);
        return getDataTable(list);
    }

    /**
     * 导出版本说明列表
     */
    @RequiresPermissions("system:versioninstruct:export")
    @Log(title = "版本说明", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VersionInstruct versionInstruct)
    {
        List<VersionInstruct> list = versionInstructService.selectVersionInstructList(versionInstruct);
        ExcelUtil<VersionInstruct> util = new ExcelUtil<VersionInstruct>(VersionInstruct.class);
        return util.exportExcel(list, "版本说明数据");
    }

    /**
     * 新增版本说明
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存版本说明
     */
    @RequiresPermissions("system:versioninstruct:add")
    @Log(title = "版本说明", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VersionInstruct versionInstruct)
    {
        return toAjax(versionInstructService.insertVersionInstruct(versionInstruct));
    }

    /**
     * 修改版本说明
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        VersionInstruct versionInstruct = versionInstructService.selectVersionInstructById(id);
        mmap.put("versionInstruct", versionInstruct);
        return prefix + "/edit";
    }

    /**
     * 修改保存版本说明
     */
    @RequiresPermissions("system:versioninstruct:edit")
    @Log(title = "版本说明", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VersionInstruct versionInstruct)
    {
        return toAjax(versionInstructService.updateVersionInstruct(versionInstruct));
    }

    /**
     * 删除版本说明
     */
    @RequiresPermissions("system:versioninstruct:remove")
    @Log(title = "版本说明", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(versionInstructService.deleteVersionInstructByIds(ids));
    }
}
